#include "stc15f2k60s2.h"
#include "Uart.h"
#include "Tim.h"
#include "Seg.h"
#include "stdio.h"
unsigned char ucSec,ucSec1;
unsigned char pucUart_Buf[2],ucUart_Num;
unsigned char pucSeg_Code[8], pucSeg_Buf[11],ucSeg_Pos;
unsigned long ulms;
void Uart_Proc();
void main(){
	Cls_Peripheral() ;
	Timer1Init();
	UartInit() ;
	while(1){
		sprintf(pucSeg_Buf,"%08u\r\n",(unsigned int)ucSec);
		Seg_Tran(pucSeg_Buf,pucSeg_Code);
		Uart_Proc();
}
}
void Time_1(void) interrupt 3 //定时器1中断函数
{ 
	 ulms++; 
	 if(!(ulms % 1000)) 
	 { 
		 ucSec++;
		 ulms=0;
	 } 
	 Seg_Disp(pucSeg_Code,ucSeg_Pos);
	 if(++ucSeg_Pos>=8) ucSeg_Pos=0;
} 
void uart_0(void) interrupt 4 
{ 
	 if(RI) 
	 { 
	 pucUart_Buf[ucUart_Num++] = SBUF; 
	 RI = 0; 
 } 
} 
void  Uart_Proc(){
	if(ucSec!=ucSec1){
		ucSec1=ucSec;
		Uart_Sendstring(pucSeg_Buf);
	}
	if(ucUart_Num == 2) 
 { 
	 ucSec = (ucSec-ucSec%100)+((pucUart_Buf[0]-'0')*10) + pucUart_Buf[1]-'0'; 
	 ucUart_Num = 0; 
 } 
}